// pages/order/list/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      address: {},
      hasAddress: false,
      total: 0,
      orders: [
          { id: 1, title: '新鲜芹菜 半斤', image: '/image/s5.png', num: 4, price: 0.01 },
          { id: 2, title: '素米 500g', image: '/image/s6.png', num: 1, price: 0.03 }
      ]
  },

  onReady() {
      this.getTotalPrice();
  },

  onShow() {
    const that = this;
    wx.getStorage({
        key: 'address',
        success: function(res) {
            that.setData({
                address: res.data,
                hasAddress: true
            });
        },
    })
  },

  /**
  * 计算总价
  */
  getTotalPrice() {
      let orders = this.data.orders;
      let total = 0;
      for (let i = 0; i < orders.length; i++) {
          total += orders[i].num * orders[i].price;
      }
      this.setData({
          total: total
      })
  },  

  toPay() {
      wx.showModal({
          title: '提示',
          content: '本系统只做演示，支付系统已屏蔽',
          text: 'center',
          complete() {
              wx.switchTab({
                  url: '/pages/user/usercenter/usercenter',
              })
          }
      })
  }

})